{{- if and .Values.cloudProviderYandex.internal.providerDiscoveryData.natInstanceName .Values.cloudProviderYandex.internal.providerDiscoveryData.monitoringAPIKey }}
  {{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: yandex-nat-instance-metrics
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "prometheus" "main" "app" "cloud-metrics-exporter")) | nindent 2 }}
spec:
  jobLabel: app
  podMetricsEndpoints:
    - port: https-metrics
      path: /metrics/compute
      scheme: https
      bearerTokenSecret:
        name: "prometheus-token"
        key: "token"
      tlsConfig:
        insecureSkipVerify: true
      honorLabels: true
      metricRelabelings:
        - sourceLabels: [ resource_id ]
          regex: {{ .Values.cloudProviderYandex.internal.providerDiscoveryData.natInstanceName }}
          action: keep
        - targetLabel: "nat_instance"
          replacement: "true"
      relabelings:
        - regex: endpoint|namespace
          action: labeldrop
        - sourceLabels: [ __meta_kubernetes_pod_ready ]
          regex: "true"
          action: keep
  selector:
    matchLabels:
      app: cloud-metrics-exporter
  namespaceSelector:
    matchNames:
      - d8-cloud-provider-yandex
  {{- end }}
{{- end }}
